<script src="__JS__/jquery.min.js?v=2.1.4"></script>
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<!--<script src="__JS__/plugins/chosen/chosen.jquery.js"></script>-->
<script src="__JS__/plugins/iCheck/icheck.min.js"></script>
<script src="__JS__/plugins/layer/laydate/laydate.js"></script>
<!--<script src="__JS__/plugins/switchery/switchery.js"></script>&lt;!&ndash;IOS开关样式&ndash;&gt;-->
<script src="__JS__/jquery.form.js"></script>
<script src="__JS__/plugins/layer/layer.js"></script>
<script src="__JS__/plugins/layui/layui.js"></script>
<script src="__JS__/wk.js"></script>
<script src="__JS__/state.js"></script>
<!--<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>-->
<!--<script src="__JS__/plugins/validate/messages_zh.min.js"></script>-->
<script src="__JS__/cropper.min.js"></script>
<script src="__JS__/plugins/footable/footable.all.min.js"></script>
<script src="__JS__/plugins/viewer/viewer.js"></script>
<!--<script src="__JS__/plugins/excel-gen/jszip.js"></script>-->
<!--<script src="__JS__/plugins/excel-gen/FileSaver.js"></script>-->
<!--<script src="__JS__/plugins/excel-gen/excel-gen.js"></script>-->
<script src="__JS__/plugins/swiper/js/swiper.min.js"></script>
<script src="__JS__/common.js"></script>
<script src="__JS__/webupload/webuploader.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.config.js" ></script>
<script src="__JS__/plugins/ueditor/ueditor.all.js" ></script>
<script src="__JS__/plugins/zTree/jquery.ztree.core-3.5.js"></script>
<script src="__JS__/plugins/zTree/jquery.ztree.excheck-3.5.js"></script>
<script src="__JS__/plugins/zTree/jquery.ztree.exedit-3.5.js"></script>
<script src="__JS__/plugins/formSelects-v4/formSelects-v4.js"></script>
<script src="__JS__/plugins/clipboard/clipboard.min.js" ></script>
<script>
    $(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    //tooltip提示
    $("[data-toggle='tooltip']").tooltip();
    //图片灯箱
    function imgDisplay(obj) {
        var src = $(obj).attr("src");
        var imgHtml = '<div class="showP"><img src=' + src + ' style="margin-top: 30px;height:90%;margin-bottom: 50px;"  /><p class="closeP"  onclick="closePicture(this)"><span class="cha">×</span></p></div>'
        $('body').append(imgHtml);
    }

    //关闭图片灯箱
    function closePicture(obj) {
        $(obj).parent("div").remove();
    }
    //关闭自动填充
    $('input').attr('autocomplete',"off");

    //layuitable表格重载
    function tableReload(){
        layui.use('table', function () {
            var table = layui.table;
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: {}
            });
        });
    }

    // //IOS开关样式配置 & chosen-select初始化
    // var elem = document.querySelector('.js-switch');
    // var switchery = new Switchery(elem, {
    //     color: '#1AB394'
    // });
    // var config = {
    //     '.chosen-select': {},
    // }
    // for (var selector in config) {
    //     $(selector).chosen(config[selector]);
    // }

    //view初始化查看图片
    function view(obj){
        $(obj).viewer({
            url: 'data-original',
        });
    }
</script>

<script>
    //chose地区三级联动
    function area(obj,type){
        if($(obj).val() == ''){
            if(type == 'province'){
                $("#city").empty();
                $("#city").append('<option value="">---- 所在市 ----</option>');
                $("#city").trigger("chosen:updated");
                $("#district").empty();
                $("#district").append('<option value="">---- 所在区 ----</option>');
                $("#district").trigger("chosen:updated");
            }else if(type == 'city'){
                $("#district").empty();
                $("#district").append('<option value="">---- 所在区 ----</option>');
                $("#district").trigger("chosen:updated");
            }
            return false;
        }
        $.ajax({
            url:"{:url('admin/Base/place')}",
            dataType:"json",
            data:'id='+$(obj).val(),
            type:'post',
            success:function(res){
                var opt = null;
                $.each(res.msg,function(key,vo){
                    opt = opt+"<option value="+vo.district_id+">"+vo.district+"</option>";
                })
                if(type == 'province'){
                    $("#city").empty();
                    $("#city").append('<option value="">---- 所在市 ----</option>');
                    $("#city").append(opt);
                    $("#city").trigger("chosen:updated");
                    $("#district").empty();
                    $("#district").append('<option value="">---- 所在区 ----</option>');
                    $("#district").trigger("chosen:updated");
                }else if(type == 'city'){
                    $("#district").empty();
                    $("#district").append('<option value="">---- 所在区 ----</option>');
                    $("#district").append(opt);
                    $("#district").trigger("chosen:updated");
                }
            }
        })
    }
    //layui三级联动
    layui.use(['form'], function() {
        var form = layui.form
            , layer = layui.layer
        form.on('select(province)', function(data){
            getArea("province",data.value);
        });
        form.on('select(city)', function(data){
            getArea("city",data.value);
        });
        function getArea(type,id){
            $.ajax({
                url:"{:url('admin/Base/place')}",
                dataType:"json",
                data:'id='+id,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
                        opt = opt+"<option value="+vo.district_id+">"+vo.district+"</option>";
                    })
                    if(type=="province"){
                        $("#city").empty();
                        $("#city").append('<option value="">---- 请选择市 ----</option>');
                        $("#district").empty();
                        $("#district").append('<option value="">---- 请选择区 ----</option>');
                        form.render('select','district');
                        $("#city").append(opt);
                        form.render('select','city');
                    }else if(type == "city"){
                        $("#district").empty();
                        $("#district").append('<option value="">---- 请选择区 ----</option>');
                        $("#district").append(opt);
                        form.render('select','district');
                    }
                }
            })
        }
    })
</script>
<script>
    // //tips框
    // $('#offAll').on('mouseover', function(){
    //     var that = this;
    //     layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 若未勾选默认禁用全部</span>', that,{tips: [2, '#F2F2F2'],time: 10000});
    // });
    // //tips框
    // $('#onAll').on('mouseover', function(){
    //     var that = this;
    //     layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 若未勾选默认启用全部</span>', that,{tips: [2, '#F2F2F2',''],time: 10000});
    // });
    //tips框
    // $('#excel').on('mouseover', function(){
    //     var that = this;
    //     layer.tips('<span style="color:#686B6D;"><i class="fa fa-info-circle"></i> 导出筛选完成数据</span>', that,{tips: [2, '#F2F2F2',''],time: 10000});
    // });
    // //关闭tips框
    // $('#offAll,#onAll,#export,#excel').on('mouseout', function(){
    //     layer.closeAll('tips');
    // });

    //layui公共操作
    layui.use(['form','table'], function() {
        var form = layui.form
            , layer = layui.layer
            ,table = layui.table
        //重置搜索框
        $('#empty').on('click', function () {
            $('.search').val('');
            // $(".search").trigger("chosen:updated");
            $('select').each(function (i, j) {
                $(j).find("option:selected").attr("selected", false);
                form.render('select')
            })
        });
        //表格排序
        table.on('sort(demo)', function(obj){
            table.reload('testReload', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态
                ,where: { //请求参数
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });
        });
        //监听搜索
        form.on('submit(LAY-search)', function (data) {
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: data.field
            });
        });
    });
    //获取serialize数据转对象
    $.fn.parseForm=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    }
</script>
